package com.uestc.soft.controller;

import com.uestc.soft.pojo.User;
import com.uestc.soft.service.UserService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@RestController
public class UserController {

    @Resource
    private UserService userService;

    // 所有这些命名按照企业规范必须一致，但在java语法本身是没有此约束的
    @RequestMapping("/user/login")//@RequestMapping提供通信信道的端口
    public Map<String, Object> login(@RequestBody User user){return userService.login(user);}

    @RequestMapping("/selectByPage")    //  根据用户传过来的用户名和年龄进行分页查询，此处网页传来四个参数，是多参数传递的写法
    public Map<String, Object> selectByPage(@RequestParam int page,
                                            @RequestParam int limit,
                                            String username,
                                            String age) {
        return userService.selectByPage(page, limit, username, age);
    }
    @RequestMapping("/user/insert")         //此处采用了对象结构传递，网页将参数打包成User对象传递
    public Map<String, Object> insert(@RequestBody User user) {
        return userService.insert(user);
    }
    @RequestMapping("/user/deleteById")
    public Map<String, Object> deleteById(@RequestParam Integer id) {
        return userService.deleteById(id);
    }

    @RequestMapping("/user/updateAge")
    public Map<String, Object> updateAge(@RequestParam Integer id, @RequestParam Integer age) {
        return userService.updateAge(id, age);
    }
    @RequestMapping("/user/deleteBlacklist")
    public Map<String, Object> deleteBlacklist(@RequestParam Integer id) {
        return userService.deleteBlacklist(id);
    }
    @RequestMapping("/user/insertBlacklist")
    public Map<String, Object> insertBlacklist(@RequestParam Integer id) {
        return userService.insertBlacklist(id);
    }
    @RequestMapping("/selectByBlacklist")    //  根据用户传过来的用户名和年龄进行分页查询，此处网页传来四个参数，是多参数传递的写法
    public Map<String, Object> selectByBlacklist(@RequestParam int page,
                                            @RequestParam int limit,
                                            String username,
                                            String age,
                                            String blacklist) {
        return userService.selectByBlacklist(page, limit, username, age, blacklist);
    }
}